#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<string.h>
int main()
{
 umask(0);
 int fd=open("log.txt",O_WRONLY|O_CREAT|O_TRUNC,0666);
 if(fd<0)
 {
   perror("open");
   return 1;
 }
 if(dup2(fd,1)>0)
 {
     //close(1);
 };//重定向成功
 printf("open fd:%d\n",fd);
 fprintf(stdout,"open fd:%d",fd);
 const char* msg="hello world";
 write(1,msg,strlen(msg));
 fflush(stdout);
 close(fd);
 return 0;









  return 0;
}
